package com.example.myxm.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.example.myxm.App;
import com.example.myxm.auth.LoginManager;
import com.example.myxm.databinding.ActivityRegisterBinding;
import com.example.myxm.module.ResultBean;
import com.example.myxm.module.UserBean;

public class RegisterActivity extends BaseActivity<ActivityRegisterBinding> {

    private  void  btnRegister(){
        getBinding().btOkRg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username = getBinding().etNameRg.getText().toString();
                String password = getBinding().etPwdRg.getText().toString();
                String phone = getBinding().etPhoneRg.getText().toString();
                ResultBean<UserBean> userBeanResultBean = App.getDbHelperStatic().registerUserBean(username,password,phone);
                if (userBeanResultBean.getCode() == LoginManager.RESULT_CODE){
                    Toast.makeText(RegisterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(RegisterActivity.this,userBeanResultBean.getMessage(),Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private  void btnCancel(){
        getBinding().btCancelRg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    @NonNull
    @Override
    protected ActivityRegisterBinding getViewBinding(@NonNull LayoutInflater inflater) {
        return ActivityRegisterBinding.inflate(inflater);
    }

    @Override
    protected void initData() {
        btnRegister();
        //“取消”按钮功能的实现
        btnCancel();
    }
}